import 'package:flutter/material.dart';
import 'package:ruitmentapp/core/extension/int_extension.dart';
import 'package:ruitmentapp/personnel/model/zj_home_model.dart';
import 'package:ruitmentapp/core/shared/size_fit.dart';
import 'package:ruitmentapp/personnel/model/zj_job_details_model.dart';

final cardRadius = 5.px;

class ZJHomeContentTitleCard extends StatelessWidget {

  final ZJJobDetailsModel _detailsModel;
  ZJHomeContentTitleCard(this._detailsModel);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: buildTitleCard(context),
    );
  }

  Widget buildTitleCard(BuildContext context) {
    return Card(
      margin: EdgeInsets.only(left: 20.px, right: 20.px, bottom: 10.px),
      elevation: 0.0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(cardRadius)),
      child: Column(
        children: <Widget>[
          buildPushTitleInfo(context),
          buildBasicInfo(context),
          buildLineInfo(),
          buildOperationInfo(context),
        ],
      ),
    );
  }

  Widget buildLineInfo() {
    return SizedBox(
        width: ZJSizeFit.screenWidth - 70.px,
        height: 1.px,
        child: Container(
          color: const Color(0xFFF3F5F7),
        )
    );
  }

  Widget buildPushTitleInfo(BuildContext context) {

    String title = _detailsModel.publishDetail.startSalary == 100.0 ? "100k以上": '${_detailsModel.publishDetail.startSalary.toInt()}-${_detailsModel.publishDetail.endSalary.toInt()}K';
    return Row(
      children: [
        Expanded(child:
        Padding(
          padding: const EdgeInsets.only(top: 20, left: 15, right: 15),
          child: Text(_detailsModel.publishDetail.pushTitle,
              textAlign:TextAlign.left,
              style: const TextStyle(
                  color: Color(0xFF3F4756),
                  fontSize: 18,
                  fontWeight: FontWeight.bold)
          ),
        ),
        ),
        // Expanded(child:
        Padding(
          padding: const EdgeInsets.only(top: 20, left: 15, right: 15),
          child: Text(title,
              textAlign:TextAlign.right,
              style: const TextStyle(
                  color: Color(0xFF5D55FC),
                  fontSize: 16)),
        ),
        // )
      ],
    );
  }

  Widget buildBasicInfo(BuildContext context) {

    String workYear = '';
    if(_detailsModel.publishDetail.workYear.contains("年")){
      workYear = _detailsModel.publishDetail.workYear;
    }else {
      if (_detailsModel.publishDetail.workYear.contains("不限")) {
        workYear = "经验不限";
      }else {
        workYear = '${_detailsModel.publishDetail.workYear}年';
      }
    }

    List rangAry = ["学历不限","初中及以下","中专/中技","高中","大专","本科","硕士","博士"];
    String endution = rangAry[_detailsModel.publishDetail.education];

    List array = [workYear, endution];
    List <Widget> textArray = [];

    for(var item in array){
      textArray.add(
          Card(
            elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
            color: const Color(0xFFF3F5F7),//设置颜色，数字为颜色饱和度
            shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(3.0))),
            child: Container(
                padding: const EdgeInsets.only(left: 10, top: 3, bottom: 3, right: 10),
                child: Text(item, style: const TextStyle(color: Color(0xFF77809E),fontSize: 12))
            ),
          )
      );
    }

    return Container(
      color: Colors.white,
      width: MediaQuery.of(context).size.width - 70,
      height: 40,
      margin: const EdgeInsets.only(top: 5,bottom: 10),
      child: Row(
        children: textArray,
      ),
    );
  }

  Widget buildOperationInfo(BuildContext context) {
    String url = _detailsModel.publishDetail.portraitUrl ??
        "https://prod.avatars.img.hr100.xin/2021-07/C9C34923CACE4854B07E5B938B215BD6.jpg";
    url = url.contains('http')
        ? url
        : "https://prod.avatars.img.hr100.xin/2021-07/C9C34923CACE4854B07E5B938B215BD6.jpg";

    String title;
    if (_detailsModel.publishDetail.tag.contains("法人")) {
      title = "法人";
    }else {
      title = _detailsModel.publishDetail.officePosition;
    }
    title = "${_detailsModel.publishDetail.referredName} · $title";

    return Row(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(left: 15, bottom: 15,top:10),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(22.px),
              child: Image.network(
                url,
                width: 45.px,
                height: 45.px,
              ),
            ),
          ),
          Expanded(child:
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.only(left: 10),
                child: Text(_detailsModel.publishDetail.createrName,
                    style: const TextStyle(color: Color(0xFF3F4756), fontSize: 16)),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 10,top: 5),
                child: Text(title,
                    style: const TextStyle(color: Color(0xFF77809E), fontSize: 12)),
              ),
            ],
          )
          ),
        ]
    );
  }
}
